module.exports = function ($scope, $state, $resource, $modalInstance, FileUploader, obj, toaster) {

  $scope.formdata = {
    'cardno': '',
    'flag': false
  }


  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };


  $scope.ok = function(){
    if(!$scope.formdata.name){
      toaster.warning({title: '', body: '姓名不能为空'});
			return;
    }
    if(!$scope.formdata.mobile){
      toaster.warning({title: '', body: '手机号格不能为空'});
			return;
    }
    if(!$scope.formdata.address){
      toaster.warning({title: '', body: '地址不能为空'});
			return;
    }
    if(!/^1\d{10}$/.test($scope.formdata.mobile)){
      toaster.warning({title: '', body: '手机号格式不正确'});
			return;
		}
    $resource('/api/ac/csc/userRegisterService/createUser', {}, {}).save($scope.formdata, function(res){
      if (res.errcode === 0) {
        toaster.success({title: '', body: '成功'});
        $state.go('app.itemInfo', {'item_id': obj.id, 'cardno': $scope.formdata.cardno, 'flag': '0'});
      } else {
        toaster.error({title: '', body: '添加失败'});
      }
    });
  };

  $scope.gogo = function(){
    if(!$scope.formdata.cardno){
      toaster.warning({title: '', body: '身份证号不能为空'});
			return;
    }
    $resource('/api/as/csc/user/getuserinfobycardno', {}, {}).save({'cardno':$scope.formdata.cardno},function (res) {
      if (res.errcode === 0 && res.data != '') {
        $state.go('app.itemInfo', {'item_id': obj.id, 'cardno': $scope.formdata.cardno, 'flag': '0'});
        $modalInstance.close();
      } else {
        $scope.formdata.flag = true;
      }
    });
  };

  
}